package com.yzh.openai.types.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
public class Response<T> implements Serializable {
    private String code;
    private String info;
    private T data;

    public Response(String code, String info) {
        this.code = code;
        this.info = info;
    }

    public Response(String code, String info, T data) {
        this.code = code;
        this.info = info;
        this.data = data;
    }

    public static Response success() {
        return new Response(Constants.ResponseCode.SUCCESS.getCode(), Constants.ResponseCode.SUCCESS.getInfo());
    }
    public static Response success(Object data) {
        return new Response(Constants.ResponseCode.SUCCESS.getCode(), Constants.ResponseCode.SUCCESS.getInfo(), data);
    }

    public static Response error() {
        return new Response(Constants.ResponseCode.UN_ERROR.getCode(), Constants.ResponseCode.UN_ERROR.getInfo());
    }
    
    public static Response error(Constants.ResponseCode responseCode) {
        return new Response(responseCode.getCode(), responseCode.getInfo());
    }
    public static Response error(String code, String msg) {
        return new Response(code, msg);
    }
}
